home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / nktools.zip / NUMBITS.ASM < prev    next >
Assembly Source File  |  1990-05-08  |  2KB  |  59 lines

  1. ;=======================================================================
  2. ; MODULE NAME:  NumBits.ASM
  3. ; DEPENDENCIES: (None)
  4. ; LAST MOD ON:  9005.08
  5. ; PROGRAMMER:   Naoto Kimura
  6. ;
  7. ;     This is the assembly code for the routine NumBits.  This routine
  8. ; returns the number of bits required for representing a value.
  9. ;
  10. ;     This file should be assembled with Turbo Assembler.  If you need
  11. ; to use another assembler, then you should keep some things in mind.
  12. ;
  13. ; The TPASCAL memory model sets up automatically:
  14. ; * the standard Turbo Pascal entry code
  15. ;      push bp
  16. ;      mov bp,sp
  17. ; * the standard Turbo Pascal exit code
  18. ;      pop bp
  19. ;      ret n
  20. ; * the order of the arguments don't need to be reversed in the
  21. ;   assembly code.
  22. ;-----------------------------------------------------------------------
  23. ; 9004.22     Naoto Kimura
  24. ;             * Initial version created
  25. ;
  26. ; Modification history:
  27. ;
  28. ;=======================================================================
  29. .MODEL   TPASCAL
  30. LOCALS
  31.  
  32. .CODE
  33.  
  34. ;-----------------------------------------------------------------------
  35. ;FUNCTION NumBits ( L : LongInt ) : Integer
  36. ;
  37. ; This funciton returns the number of bits required for representing a 
  38. ; value.
  39. ;
  40. ; REGISTER USAGE:  AX -- Return value
  41. ;                  BX -- Zeroed
  42. ;-----------------------------------------------------------------------
  43. NumBits        PROC FAR L:DWORD
  44.         PUBLIC    NumBits
  45.         les    bx,[L]        ; es:bx <-- L
  46.         mov    ax,es        ; ax <-- HiWord(L)
  47.         or    ax,ax
  48.         jz    @@ShiftIt
  49.         xchg    ax,bx        ; bx <--> ax
  50.         mov    ax,16
  51. @@ShiftIt:    shr    bx,1
  52.         inc    ax
  53.         or    bx,bx
  54.         jnz    @@ShiftIt
  55.         ret
  56. NumBits        ENDP
  57.  
  58. END
  59.